<!doctype html>
<html>
<body>
<script>
var Person = function(name){
  if(!(this instanceof Person)){
    return new Person(name);
  }
  this.name = name;
}

var p = new Person('laoyao');
alert(p.name);

var p = Person('xxx');
alert(p.name);
</script>
</body>
</html>